package b4.view.component.task
{
	import org.aswing.Component;
	import org.aswing.Icon;
	import org.aswing.JTextComponent;
	import org.aswing.JTree;
	import org.aswing.border.EmptyBorder;
	import org.aswing.tree.TreeCell;
	
	public class TaskTreeCell extends JTextComponent implements TreeCell 
	{
		protected var expanded_folder_icon:Icon;
		protected var collapsed_folder_icon:Icon;
		protected var leaf_icon:Icon;
	
		private var value:*;
		
		public function TaskTreeCell(){
			super();
			setEditable(false);
			setBorder(new EmptyBorder());
		}
		
		public function setCellValue(value:*) : void {
			readyToPaint = true;
			this.value = value;
			this.setHtmlText(value);
		}
		
		public function getCellValue():*{
			return value;
		}
		
		public function getCellComponent() : Component {
			return this;
		}
		
		public function setTreeCellStatus(tree : JTree, selected : Boolean, expanded : Boolean, leaf : Boolean, row : int) : void {
			if(expanded_folder_icon == null){
				expanded_folder_icon = createExpandedFolderIcon(tree);
				//make it can get image from tree ui properties
//				getUI().putDefault("Tree.folderExpandedImage", tree.getUI().getDefault("Tree.folderExpandedImage"));
			}
			if(collapsed_folder_icon == null){
				collapsed_folder_icon = createCollapsedFolderIcon(tree);
				//make it can get image from tree ui properties
//				getUI().putDefault("Tree.folderCollapsedImage", tree.getUI().getDefault("Tree.folderCollapsedImage"));
			}
			if(leaf_icon == null){
				leaf_icon = createLeafIcon(tree);
				//make it can get image from tree ui properties
//				getUI().putDefault("Tree.leafImage", tree.getUI().getDefault("Tree.leafImage"));
			}
			
//			if(selected){
//				setBackground(tree.getSelectionBackground());
//				setForeground(tree.getSelectionForeground());
//			}else{
//				setBackground(tree.getBackground());
//				setForeground(tree.getForeground());
//			}
			setFont(tree.getFont());
//			if(leaf){
//				setIcon(getLeafIcon());
//			}else if(expanded){
//				setIcon(getExpandedFolderIcon());
//			}else{
//				setIcon(getCollapsedFolderIcon());
//			}
		}
	
		protected function createExpandedFolderIcon(tree:JTree):Icon{
			return tree.getUI().getIcon("Tree.folderExpandedIcon");
		}
		protected function createCollapsedFolderIcon(tree:JTree):Icon{
			return tree.getUI().getIcon("Tree.folderCollapsedIcon");;
		}
		protected function createLeafIcon(tree:JTree):Icon{
			return tree.getUI().getIcon("Tree.leafIcon");;
		}
	}
}